package org.newdawn.yapgame;

import org.lwjgl.Sys;


/**
 * A wrapper class that provides timing methods. This class provides us with a
 * central location where we can add our current timing implementation.
 * Initially, we're going to rely on the GAGE timer. (@see
 * http://java.dnsalias.com)
 * 
 * @author Marko Walther
 * @author Kevin Glass
 */
public class SystemTimer
{

	protected static long frequency = Sys.getTimerResolution();
    /**
     * Get the high resolution time in milliseconds
     * 
     * @return The high resolution time in milliseconds
     */
    public static long getTime()
    {
    	// use the lwjgl timer
    	// we get the "timer ticks" from the high resolution timer
    	// multiply by 1000 so our end result is in milliseconds
    	// then divide by the number of ticks in a second giving
    	// us a nice clear time in milliseconds
    	return (Sys.getTime() * 1000) / frequency;
    }

    /**
     * Sleep for a fixed number of milliseconds.
     * 
     * @param duration
     *            The amount of time in milliseconds to sleep for
     * @throws InterruptedException
     */
    public static void sleep(long duration) throws InterruptedException
    {
    	if (duration >= 0)
    		Thread.sleep(duration);
    }
}